<%
layout("/layouts/platform.html"){
%>
	<header class="header navbar bg-white shadow">
	  	<a href="${base}/platform/wx/conf/menu/index/${wxid}" data-pjax id="_reload"><span id="_reload1"></span></a>
	    <div class="btn-group">
	        <div >
	            <select id="wxid" name="wxid" class="form-control">
	                <% for(o in wxList){
	                %>
	                <option value="${o.id}" <%if(o.id==wxid){%>selected<%}%> >${o.appname}</option>
	                <%
	                } %>
	            </select>
	        </div>
	    </div> 
	    <div class="pull-right ">
	    	<a class="btn btn-default navbar-btn" href="${base}/platform/wx/conf/menu/add/${wxid}" data-pjax><i class="fa fa-plus"></i> 添加菜单</a>
	    	<a class="btn btn-default navbar-btn" href="javascript:sort()"> 保存排序</a>
	    	<a class="btn btn-default navbar-btn" href="javascript:complete()"><i class="ti-share"></i> 推送到微信</a>
		</div>
	</header>



	
	<div class="panel-body" style="padding-top: 70px;">
		<div class="box">
			<div class="box-body">
			    <div class="panel">
			        <div class="panel-heading no-b">
			        </div>
			        <div class="panel-body" style="padding-top: 30px;">
			            
			            <div class="cf nestable-lists">
			                <div class="dd" id="nestable3">
			                    <% if(!isEmpty(firstMenus)){ %>
			                    <ol class="dd-list">
			                        <% for(firstMenu in firstMenus){ %>
			                        <li class="dd-item dd3-item" data-id="${firstMenu.id}">
			                            <div class="dd-handle dd3-handle">Drag</div>
			                            <div class="dd3-content">${firstMenu.menuName!} <span style="color: deepskyblue"> ${firstMenu.menuKey!}${firstMenu.url!}</span>
			                                 		<div class="pull-right">
														<a class="btn btn-xs btn btn-default " href="${base}/platform/wx/conf/menu/edit/${firstMenu.id!}" ><i class="fa fa-edit"></i>&nbsp;修改</a> 
													 	<a class="btn btn-xs btn btn-default " href="javascript:;" onclick="del('${firstMenu.id!}')"><i class="glyphicon glyphicon-trash"></i>删除</a> 
													</div> 
			                            </div>
			                            <% if(!isEmpty(@secondMenus.get(firstMenu.path))){ %>
			                            <ol class="dd-list">
			                                <% for(secondMenu in @secondMenus.get(firstMenu.path)){  %>
			                                <li class="dd-item dd3-item" data-id="${secondMenu.id}">
			                                    <div class="dd-handle dd3-handle">Drag</div>
			                                    <div class="dd3-content">${secondMenu.menuName!}<span style="color: deepskyblue"> ${secondMenu.menuKey!}${secondMenu.url!}</span>
			                                       <div class="pull-right">
														<a class="btn btn-xs btn btn-default " href="${base}/platform/wx/conf/menu/edit/${secondMenu.id!}" ><i class="fa fa-edit"></i>&nbsp;修改</a> 
													 	<a class="btn btn-xs btn btn-default " href="javascript:;" onclick="del('${secondMenu.id!}')"><i class="glyphicon glyphicon-trash"></i>删除</a> 
													</div> 
			                                    </div>
			                                </li>
			                                <% }%>
			                            </ol>
			                            <% } %>
			                        </li>
			                        <% } %>
			
			                    </ol>
			                    <%}else{%>
			                    <ol class="dd-list" style="padding-top: 10px;">未配置</ol>
			                    <%}%>
			                </div>
			            </div>
			
			        </div>
			    </div>
			</div>
		</div>
	</div>
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">删除菜单</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        删除后无法恢复，请谨慎操作！
                        <br/>确定要删除吗？
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button id="ok" type="button" class="btn btn-primary" data-loading-text="正在删除...">确 定</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function del(id){
        var dialog = $("#dialogDelete");
        dialog.modal("show");
        dialog.find("#ok").unbind("click");
        dialog.find("#ok").bind("click", function(event){
            $.post("${base}/platform/wx/conf/menu/delete/"+id,{},function(data){
                //重置按钮状态，关闭提示框
                dialog.modal("hide");
                if(data.code==0){
                    Toast.success(data.msg);
                    window.location.reload();
                }else{
                    Toast.error(data.msg);
                }
            },"json");
        });
    }
    var ids=[];
    function getId(ob){
        $.each(ob,function(i,o){
            ids.push(o.id);
            if(o.children){
                getId(o.children);
            }
        });
    }
    function sort(){
        ids=[];
        getId($("#nestable3").nestable('serialize'));
        $.post("${base}/platform/wx/conf/menu/sortDo", {wxid:'${wxid}',ids: ids.toString()}, function (data) {
            if (data.code == 0) {
                Toast.success(data.msg);
            } else {
                Toast.error(data.msg);
            }
        }, "json");
    }
    function complete(){
        sublime.showLoadingbar($(".main-content"));
        $.post("${base}/platform/wx/conf/menu/pushMenu/${wxid}", {}, function (data) {
            sublime.closeLoadingbar($(".main-content"));
            if (data.code == 0) {
                Toast.success(data.msg);

            } else {
                Toast.error(data.msg);
            }
        }, "json");
    }

    $(function () {
        $("#nestable3").nestable();
        $("#wxid").on("change",function(){
            $("#_reload").attr("href","${base}/platform/wx/conf/menu/index/"+$(this).val());
            $("#_reload1").trigger("click");
        });
    });

</script>

<%}%>
